package com.situ.javase.day6;

import java.util.Scanner;

import org.junit.Test;

public class Shuzuzuoye {
@Test
public void test2() {
	//1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	//求出上面数组中0-9分别出现的次数
	int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	for (int i = 0; i <= 9; i++) {
		int count = 0;
		for (int j = 0; j < scores.length; j++) {
			if (i == scores[j]) {
				count++;
			}
		}
		System.out.println(i+"出现的次数"+count);
	}
}
@Test
//1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//求出上面数组中0-9分别出现的次数
public void test3() {
	int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	int num [] = new int[10];
	for (int i = 0; i < scores.length; i++) {
	 switch (scores[i]) {
	case 0:
		num[0] ++;
		break;
	case 1:
		num[1]++;
		break;
	case 2:
		num[2]++;
		break;
	case 3:
		num[3]++;
		break;
	case 4:
		num[4]++;
		break;
	case 5:
		num[5]++;
		break;
	case 6:
		num[6]++;
		break;
	case 7:
		num[7]++;
		break;
	case 8:
		num[8]++;
		break;
	case 9:
		num[9]++;
		break;
	 	}
	}
	for (int i = 0; i < num.length; i++) 
		 System.out.println(i + "的个数"+ num[i]);
	}

@Test   //第2题
public void test4() {
	int oddsum = 0;
	int evensum = 0;
	int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	for (int i = 0; i < scores.length; i++) {
		
		if (i % 2 == 0) {
			oddsum++;
		}else {
			evensum++;
		}
	}
	System.out.println(oddsum);
	System.out.println(evensum);
	
}

@Test    //第三题
public void test5() {
	int[]  array = new int[4];
	array[0] = 48;
	array[1] = 88;
	array[2] = 68;
	array[3] = 99;
	int sum = 0;
	for (int i = 0; i < array.length; i++) {
		sum = sum + array[i];
	}
	System.out.println(sum / array.length);
}

	/*
	 * 5.B 
	 * 6.D 
	 * 7.A (B中super 是变量引用) 
	 * 8.B 
	 * 9.A 
	 * 10.C 
	 * 11.B 
	 * 12.D 
	 * 13.C 
	 * 14.D 
	 * 15.C
	 */



@Test //16题
public void test6() {
	Scanner scanner = new Scanner(System.in);
	   System.out.println("请输入一个五位数");
	   String str = scanner.next();// "abcba"
	   char[] array = str.toCharArray();
	   if ((array[0] == array[4]) && array[1] == array[3]) {
		System.out.println("该数为回文数");
	}else {
		System.out.println("该数不是回文数");
	}
}

@Test //17题      太难了！！！！！
public void test7() {
	Scanner scanner = new Scanner(System.in);
	   System.out.println("请输入一个字符串");
	   String str = scanner.nextLine();
	   char[] array = str.toCharArray();//将字符串转换为字符数组；
	   for (int i = 0; i < array.length; i++) {
		int count = 0;
		char ch =array[i];
		boolean flag = true;
		for (int j = 0; j < i; j++) {
			if (array[j] == ch) {
				flag = false;
				break;
			}
		}
				if (flag) {
					for (int k = 0; k < array.length; k++) {
					if (array[k] == ch) {
						count++;
					}
				}
					System.out.println(array[i]+"出现的次数"+count);	
			}
		}
	}

@Test  //17题正常做法；
public void test8() {
	Scanner scanner = new Scanner(System.in);
	System.out.println("请输入字符串：");
	String str = scanner.nextLine();
	char[] array = str.toCharArray();
	int word = 0;
	int space = 0;
	int num = 0;
	int qita = 0;
	for (int i = 0; i < array.length; i++) {
		if ((array[i] >= 'A' && array[i] <= 'Z') || (array[i] >= 'a' && array[i] <= 'z')) {
			word++;
			continue;
		} else if (array[i] == ' ') {
			space++;
			continue;
		} else if (array[i] >= '0' && array[i] <= '9') {
			num++;
			continue;
		} else {
			qita++;
			continue;
		}
	}
	System.out.println("英文字母个数:" + word + "\n" + "空格个数:" + space + "\n" + "数字个数:" + num + "\n" + "其他字符个数:"
			+ qita);
}

@Test //18题
//int[] = {23,4,56,78,99,22,67}找出数组里面的最大值和最小值;
public void test9() {
	int[] array = {23,4,56,78,99,22,67};
	int temp = 0;
	for (int i = 0; i < array.length - 1; i++) {
		//System.out.println(array[i]);
		for (int j = 0; j < array.length - 1 -i; j++) {
			if (array[j] > array[j + 1]) {
				 temp = array[j];
				 array[j] = array[j + 1];
				 array[j + 1] = temp;
			}
		}
	}
	System.out.println("最大值为"+ array[6]);
	System.out.println("最小值为"+ array[0]);
}
}
